package com.it.plic.Field;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

/**
 * @author げっしょく
 * @date 2021/8/9
 */
public class Test2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException, IllegalAccessException, InstantiationException {
        //method1();
        //创建class对象
        Class aClass = Class.forName("com.it.plic.Field.Student");
        //获取name这个对象
        Field menoy = aClass.getDeclaredField("menoy");
        menoy.setAccessible(true);
        //创建这个类的对象
        Student s = (Student) aClass.newInstance();
        System.out.println(menoy.get(s));

    }

    private static void method1() throws ClassNotFoundException, NoSuchFieldException, InstantiationException, IllegalAccessException {
        //创建class对象
        Class aClass = Class.forName("com.it.plic.Field.Student");
        //获取name这个对象
        Field name = aClass.getField("name");
        //创建这个类的对象
        Student c = (Student) aClass.newInstance();
        //进行赋值
        String zhangsan = "zhangsan";
        name.set(c, zhangsan);
        System.out.println(c);
    }
}
